package com.ls.stream;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Arrays;

public class StreamTest {
	public static void main(String[] args) {
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			
			String str = "snp";
			byte[] aaa=EStringUtils.getBytes(str);
			System.out.println(Arrays.toString(aaa));
//			dos.write(aaa, 0, 20);
			dos.writeUTF(null);
			dos.writeByte(400);
			dos.writeByte(1);
			dos.writeByte(1);
			dos.writeShort(217);
		} catch (IOException e) {
			e.printStackTrace();
		}

		byte[] aa = baos.toByteArray();
		System.out.println(Arrays.toString(aa));
		ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
		DataInputStream dis = new DataInputStream(bais);

		try {
			System.out.println(dis.readByte());
			System.out.println(dis.readByte());
			System.out.println(dis.readByte());
			System.out.println(dis.readShort());
		} catch (IOException e) {
			e.printStackTrace();
		}
		try {
			dos.close();
			dis.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
